import { resolve } from 'path'
import { dynamicImport } from 'vite-plugin-dynamic-import'
import { defineConfig } from 'vite'
// 自动导入vue中hook reactive ref等
import AutoImport from 'unplugin-auto-import/vite'
//自动导入ui-组件 比如说ant-design-vue  element-plus等
import Components from 'unplugin-vue-components/vite'
//naive
import { NaiveUiResolver } from 'unplugin-vue-components/resolvers'

import vue from '@vitejs/plugin-vue'

// windicss
import WindiCSS from 'vite-plugin-windicss'

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [
    vue(),
    WindiCSS(),
    AutoImport({
      //安装两行后你会发现在组件中不用再导入ref，reactive等
      imports: [
        'vue',
        'vue-router',
        {
          'naive-ui': [
            'useDialog',
            'useMessage',
            'useNotification',
            'useLoadingBar'
          ]
        }
      ],

      //存放的位置
      dts: 'src/auto-import.d.ts',
      resolvers: [NaiveUiResolver()]
    }),

    Components({
      // 引入组件的,包括自定义组件
      // 存放的位置
      dts: 'src/components.d.ts',
      resolvers: [NaiveUiResolver()]
    }),

    dynamicImport()
  ],
  resolve: {
    // ↓路径别名
    alias: {
      '@': resolve(__dirname, './src')
    }
  },
  css: {
    preprocessorOptions: {
      scss: {
        additionalData: '@import "@/styles/variable.scss";'
      }
    }
  }
})
